package org.cholm.drtest.proxy;

import org.json.JSONObject;

public class WithMeta {

	/** Meta data */
	public MediaMetaData meta = null;
	/**
	 * Set key on meta data from JSON field
	 *
	 * @param tgt  Key identifier
	 * @param src  JSON source field
	 * @param json JSON object
	 */
	protected void setKey(String tgt, String src, JSONObject json) {
		if (!json.has(src)) return;
		meta.putString(tgt, json.optString(src));
	}
	/**
	 * Get a JSON field
	 *
	 * @param src  Name of JSON field
	 * @param json JSON object
	 *
	 * @return Value of field (if it exists) as a string, or null
	 */
	protected String getJSON(String src, JSONObject json) {
		if (!json.has(src)) return null;
		return json.optString(src);
	}
	/**
	 * Constructor
	 */
	public WithMeta()
	{
		super();
		meta = new MediaMetaData();
	}
	/**
	 * Constructor w/media type
	 *
	 * @param mediaType Media type
	 */
	public WithMeta(int mediaType) {
		super();
		meta = new MediaMetaData(mediaType);
	}
	/**
	 * Constructor from parent media type
	 *
	 * @param parent Parent
	 */
	public WithMeta(MediaMetaData parent)
	{
		super();
		meta = new MediaMetaData(parent.getMediaType());
		for (String key : parent.keySet())
			meta.putString(key, parent.getString(key));
		for (WebImage img : parent.getImages())
			meta.addImage(img);
	}
	public MediaMetaData getMeta() { return meta; }
}
/* EOF */
